package com.xm.service.service.impl;

import com.alibaba.excel.EasyExcel;
import com.xm.listener.MemberListener;
import com.xm.mapper.MemberMapper;
import com.xm.pojo.Member;
import com.xm.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

/**
 * 业务逻辑层（service）：处理业务，做一些判断等等...
 */
@Service//PatientService ps = new PatientServiceImpl(); -> ps对象已经放到spring容器中
public class MemberServiceImpl implements MemberService {
    @Autowired
    private MemberMapper memberMapper;

    @Override
    public List<Member> findAll() {
        return memberMapper.findAll();
    }

    @Override
    public void add(Member member) {
        memberMapper.add(member);
    }

    @Override
    public void logicDelete(Member member) {
        memberMapper.logicDelete(member);
    }

    @Override
    public void updateMember(Member member) {
        memberMapper.updateMember(member);
    }

    @Override
    public void batchDel(Integer[] ids) {
        memberMapper.batchDel(ids);
    }

    @Override
    public List<Member> findByIds(Integer[] ids) {
        return memberMapper.findByIds(ids);
    }

    @Override
    public void upload(MultipartFile file) {
        InputStream inputStream = null;

        //获取输入流
        try {
            inputStream = file.getInputStream();
        } catch (IOException e) {
            e.printStackTrace();
        }

        // 这里 需要指定读用哪个class去读，然后读取第一个sheet 文件流会自动关闭
        EasyExcel.read(inputStream,Member.class, new MemberListener(memberMapper)).sheet().doRead();
    }

    @Override
    public List<Member> findDeleted() {
        return memberMapper.findDeleted();
    }

    @Override
    public void restoreById(Member member) {
        memberMapper.restoreById(member);
    }

    @Override
    public void batchRes(Integer[] ids) {
        memberMapper.batchRes(ids);
    }

    @Override
    public void deleteById(String memberid) {
        memberMapper.deleteById(memberid);
    }

    @Override
    public List<Member> findById(String v) {
        return memberMapper.findById(v);
    }

    @Override
    public List<Member> findByMembername(String v) {
        return memberMapper.findByMembername(v);
    }

    @Override
    public List<Member> findByNick(String v) {
        return memberMapper.findByNick(v);
    }

    @Override
    public List<Member> findByPhone(String v) {
        return memberMapper.findByPhone(v);
    }

    @Override
    public List<Member> findByQQ(String v) {
        return memberMapper.findByQQ(v);
    }

    @Override
    public Integer getmemberNum() {
        return memberMapper.getmemberNum();
    }


}
